<?php
//------------------------------------------------------------------------------
// File               : V_SanphamListSearch
// Modification       :
//------------------------------------------------------------------------------
// Date(yyyy.mm.dd)   Developer                       Action
//------------------------------------------------------------------------------
// 2007.03.15         Oanhhtk                         Created
//------------------------------------------------------------------------------

function V_SanphamListSearchAdvance(&$arrayData,$action){
	global $LANG,$db;
    $ulr = "?".MODUL."=sanpham&".ACTION."=";
	include_once(DIR_MODEL."md_cat_san_pham.class.php");
	$objcatSanpham = new MD_CatSanpham($db);
	//hang sx
	include_once(DIR_MODEL."md_hang_sx.class.php");
	$objHangsx = new MD_Hangsx($db);
	
	//CM_showError();
	//phan trang
	$totalRows = 0;
	$curPage =1;
	$strStart =0;
	$strEnd=0;
	$totalRecord = 10;
	
	$totalRows=count($arrayData);

	$curPage =CM_getParameter("curPg");
	if(((int)$curPage)==0) $curPage =1;
	
	$totalPage = 	(int)($totalRows/ $totalRecord);
	if($totalRows % $totalRecord > 0 ) $totalPage ++;
	
	if($totalRows >0){
		$strStart = ($curPage -1) * $totalRecord +1;
		$strEnd   = ($curPage )   * $totalRecord ;
		if($strEnd  > $totalRows ) $strEnd  = $totalRows;
	}
	
	$tong = sizeof($arrayData);
?>
<script>
function GotoPage(iPage) 
{
	document.frmContent.curPg.value = iPage;
	document.frmContent.action = "../run/main.php?modul=sanpham&action=search_advance_text&curPage="+iPage;
	document.frmContent.submit();
}
</script>

<form action="" name="frmContent" method="post">
<div class="title" style="margin-left:10px; width:10px; height:30px; float:left"></div>
<p style="float:left; line-height:30px; font-weight:bold; color:#FFFFFF; background: url(../images/modul_c.gif);">Kết quả tìm kiếm nâng cao</p>
<div class="title2" style="width:10px; height:30px; float:left"></div>
<div style="clear:both" class="clear_ie"></div>
<div class="bg_l_t"><div class="bg_r_t"><div class="bg_c_t"></div></div></div>
<div class="cat_sp_cen">
<?
if($totalRows>0){
	$curRow=0;
	$i=0;
?>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<?
foreach($arrayData as $row){
	$arrayDataCatSP = $objcatSanpham -> getById2($row['id_loai_sp']);
	$parent_id = $arrayDataCatSP['parent_id'];
	$curRow ++;
	if( $curRow < $strStart ) continue;
	if( $curRow > $strEnd )  break;
	$i+1;
?>
	<tr style="height:120px">
		<td width="120" align="center">
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td align="center" style="padding-bottom:3px; ">
					<?
					$arrayDataHangsx = $objHangsx -> getById($row['hang_sx']);
					?>
					<img src="<?=DIR_IMAGES_VIEW_HANG_SX.$arrayDataHangsx['ten_anh']?>" width="81" />
					</td>
				</tr>
				<tr>
					<td style="border:1px solid #E9AE95; border-collapse:collapse;" align="center">
						<img src="<?=DIR_IMAGES_VIEW.$row['anh_sp']?>" width="100" height="100" />
					</td>
				</tr>
			</table>		
		</td>
		<td width="735" valign="top" style="padding-right:5px; padding-top:3px; padding-left:20px;  ">
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td class="cat_ten_sp" style="line-height:20px;">
						<span style="text-transform:uppercase; "><?=$row['ten_sp']?></span>
					</td>
				</tr>
				<tr>
					<td style="line-height:20px; ">
						<?=$row['mo_ta_sp']?>
					</td>
				</tr>
			</table>
		</td>
		<td width="100">Giá sản phẩm:<br /><span class="gia_moi"><?=to_money($row['gia_sp'])?> VNĐ</span><br /><br />
		<span class="muangay"><a href="?modul=giohang&action=View&id=<?=$row["id"]?>">Mua ngay</a></span><br />
		<span class="chitiet_sp"><a href="?modul=sanpham&action=View&parent_id=<?=$parent_id?>&id_loai_sp=<?=$row['id_loai_sp']?>&id=<?=$row['id']?>">Chi tiết</a></span>
		</td>
	</tr>
<?
	$tong--;
	if( $curRow < $strEnd ){
?>
	<tr><td colspan="3"><hr style="border-bottom:0.1em solid #FF0000;" /></td></tr>
<?
	}
}//end foreach
?>
	<tr>
		<td colspan="3" style="padding-top:20px; ">
			<?
			if($totalPage>1){	
			?>
			<table  cellpadding="0" cellspacing="0" align="center">
				<br>
				<tr>
					<td class="pagingIntact">
						<a href="javascript:GotoPage('1')">&nbsp;&laquo;&nbsp;Trang đầu&nbsp;</a>
					</td>
					<td class="pagingSpace"></td>
					<?
					for($i=1;$i<= $totalPage;$i++){
						if($i < $curPage + 11 && $i > $curPage - 11){
							if($i == $curPage){
					?>
					<td class="pagingViewed">
						<?=$i?>
					</td>
					<td class="pagingSpace"></td>
					<?
							}
							if($i != $curPage){
					?>
					<td class="pagingIntact">
						<a href="javascript:GotoPage('<?=$i?>')"><?=$i?></a>
					</td>
					<td class="pagingSpace"></td>
					<?
							}
						} 
					}
					?>
					<td class="pagingIntact">
						<a href="javascript:GotoPage('<?=$totalPage?>')">&nbsp;Trang cuối&nbsp;&raquo;&nbsp;</a>
					</td>
				</tr>
			</table>
			<?
			}//end if($totalPage>1)
			?>
		</td>
	</tr>

</table>
<?
}//end if empty
?>

</div><!-- cat_sp_cen -->
<div class="bg_l_b"><div class="bg_r_b"><div class="bg_c_b"></div></div></div>
<input type="hidden"  name="curPg"  value="0" >
<input type="hidden"  name="id"  value="<?=CM_getParameter('id')?>" >
<input type="hidden"  name="textfield"  value="<?=CM_getParameter('textfield')?>" >
</form>
<?
	foreach ($_POST as $key => $value) {
		$value = htmlspecialchars( CM_getParameter($key));
		echo '<input type=hidden  name="'.$key.'"  value="'.$value.'" >';
		echo "\n";
	}
}
?>